<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="举报编号" prop="lzjbCode">
        <el-input
          v-model="queryParams.lzjbCode"
          placeholder="请输入举报code"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="来源系统" prop="lzjbXtCode">
        <el-select v-model="queryParams.lzjbXtCode" placeholder="请选择来源系统" clearable size="small">
          <el-option
            v-for="dict in lzjbXtCodeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="联系电话" prop="lzjbPhone">
        <el-input
          v-model="queryParams.lzjbPhone"
          placeholder="请输入联系电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="举报类型" prop="lzjbType">
        <el-input
          v-model="queryParams.lzjbType"
          placeholder="请输入举报类型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="举报状态" prop="lzjbState">
        <el-select v-model="queryParams.lzjbState" placeholder="请选择举报状态" clearable size="small">
          <el-option
            v-for="dict in lzjbStateOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['lzjb:lzjbinfo:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" border stripe :data="lzjbinfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="举报编号" align="center" prop="lzjbCode" />
      <el-table-column label="来源系统" align="center" prop="lzjbXtCode" :formatter="lzjbXtCodeFormat" />
      <el-table-column label="联系电话" align="center" prop="lzjbPhone" />
      <el-table-column label="创建人地址" align="center" prop="lzjbYl1" width="160"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="160"/>
      <el-table-column label="举报类型" align="center" prop="lzjbType"/>
      <el-table-column label="举报状态" align="center" prop="lzjbState" :formatter="lzjbStateFormat" />
      <el-table-column label="举报内容" align="center" prop="lzjbContent" width="300px"/>
      <!-- <el-table-column label="用户unionid" align="center" prop="lzjbUserUnionid" />
      <el-table-column label="用户openid" align="center" prop="lzjbUserOpenid" /> -->

      <el-table-column label="处理结果" align="center" prop="lzjbCl1" width="300px"/>
      <!-- <el-table-column label="处理结果2" align="center" prop="lzjbCl2" /> -->
      <el-table-column label="内部备注" align="center" prop="lzjbRemark" width="300px"/>
      <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleOpenFile(scope.row)"
          >查看附件</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-if="scope.row.lzjbState=='HN_LZJB_CLZ'&&scope.row.isActive=='1'"
          >处理</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改廉正举报对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!-- <el-form-item label="是否有效" prop="isActive">
          <el-input v-model="form.isActive" placeholder="请输入是否有效" />
        </el-form-item>
        <el-form-item label="租户id" prop="lesseeId">
          <el-input v-model="form.lesseeId" placeholder="请输入租户id" />
        </el-form-item>
        <el-form-item label="举报code" prop="lzjbCode">
          <el-input v-model="form.lzjbCode" placeholder="请输入举报code" />
        </el-form-item>
        <el-form-item label="来源系统code">
          <el-select v-model="form.lzjbXtCode" placeholder="请选择来源系统code">
            <el-option
              v-for="dict in lzjbXtCodeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="来源系统名称" prop="lzjbXtName">
          <el-input v-model="form.lzjbXtName" placeholder="请输入来源系统名称" />
        </el-form-item>
        <el-form-item label="联系电话" prop="lzjbPhone">
          <el-input v-model="form.lzjbPhone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="举报类型" prop="lzjbType">
          <el-input v-model="form.lzjbType" placeholder="请输入举报类型" />
        </el-form-item>
        <el-form-item label="举报内容" prop="lzjbContent">
          <el-input v-model="form.lzjbContent" placeholder="请输入举报内容" />
        </el-form-item>
        <el-form-item label="用户unionid" prop="lzjbUserUnionid">
          <el-input v-model="form.lzjbUserUnionid" placeholder="请输入用户unionid" />
        </el-form-item>
        <el-form-item label="用户openid" prop="lzjbUserOpenid">
          <el-input v-model="form.lzjbUserOpenid" placeholder="请输入用户openid" />
        </el-form-item>
        <el-form-item label="举报状态">
          <el-select v-model="form.lzjbState" placeholder="请选择举报状态">
            <el-option
              v-for="dict in lzjbStateOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="处理结果" prop="lzjbCl1">
          <el-input type="textarea" rows="5" v-model="form.lzjbCl1" placeholder="请输入处理结果" />
        </el-form-item>
        <!-- <el-form-item label="处理结果2" prop="lzjbCl2">
          <el-input v-model="form.lzjbCl2" placeholder="请输入处理结果2" />
        </el-form-item> -->
        <el-form-item label="内部备注" prop="lzjbRemark">
          <el-input type="textarea" rows="5" v-model="form.lzjbRemark" placeholder="请输入内部备注" />
        </el-form-item>
       <!--  <el-form-item label="预留1" prop="lzjbYl1">
          <el-input v-model="form.lzjbYl1" placeholder="请输入预留1" />
        </el-form-item>
        <el-form-item label="预留2" prop="lzjbYl2">
          <el-input v-model="form.lzjbYl2" placeholder="请输入预留2" />
        </el-form-item>
        <el-form-item label="预留3" prop="lzjbYl3">
          <el-input v-model="form.lzjbYl3" placeholder="请输入预留3" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="查看附件" :visible.sync="openFile" width="800px" append-to-body>
      <el-carousel indicator-position="outside" height="500px" :autoplay="false">
        <el-carousel-item v-for="item in fileList" :key="item.id" >
          <div class="file-preview">
            <img v-if="item.sourcessType=='LZJB_IMG'" :src="item.fileFullUrl" />
            <video v-if="item.sourcessType=='LZJB_VIDEO'" :src="item.fileFullUrl" controls/>
          </div>
        </el-carousel-item>
      </el-carousel>
    </el-dialog>

  </div>
</template>

<script>
import { getFileList } from '@/api/basic/file'
import { listLzjbinfo, getLzjbinfo, delLzjbinfo, addLzjbinfo, updateLzjbinfo, exportLzjbinfo } from "@/api/lzjb/lzjbinfo";

export default {
  name: "Lzjbinfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 廉正举报表格数据
      lzjbinfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 来源系统code字典
      lzjbXtCodeOptions: [],
      // 举报状态字典
      lzjbStateOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        lzjbCode: undefined,
        lzjbXtCode: undefined,
        lzjbPhone: undefined,
        lzjbType: undefined,
        lzjbUserUnionid: undefined,
        lzjbUserOpenid: undefined,
        lzjbState: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        lzjbCl1:[
          { required: true, message: "处理结果必填", trigger: "blur" }
        ]
      },
      fileList:[],
      openFile:false
    };
  },
  created() {
    this.getList();
    this.getDicts("HN_LZJB_TYPE").then(response => {
      this.lzjbXtCodeOptions = response.data;
    });
    this.getDicts("HN_LZJB_STATE").then(response => {
      this.lzjbStateOptions = response.data;
    });
  },
  methods: {
    handleOpenFile(row){
      getFileList({sourcessId:row.id}).then(res=>{
        this.fileList = res.data || res.rows || []
        this.openFile = true
      })
    },
    /** 查询廉正举报列表 */
    getList() {
      this.loading = true;
      listLzjbinfo(this.queryParams).then(response => {
        this.lzjbinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 来源系统code字典翻译
    lzjbXtCodeFormat(row, column) {
      return this.selectDictLabel(this.lzjbXtCodeOptions, row.lzjbXtCode);
    },
    // 举报状态字典翻译
    lzjbStateFormat(row, column) {
      if(row.isActive=='1'){
        return this.selectDictLabel(this.lzjbStateOptions, row.lzjbState);
      }
      return '已撤销'
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        isActive: undefined,
        lesseeId: undefined,
        lzjbCode: undefined,
        lzjbXtCode: undefined,
        lzjbXtName: undefined,
        lzjbPhone: undefined,
        lzjbType: undefined,
        lzjbContent: undefined,
        lzjbUserUnionid: undefined,
        lzjbUserOpenid: undefined,
        lzjbState: undefined,
        lzjbCl1: undefined,
        lzjbCl2: undefined,
        lzjbRemark: undefined,
        lzjbYl1: undefined,
        lzjbYl2: undefined,
        lzjbYl3: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加廉正举报";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getLzjbinfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改廉正举报";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            this.form.lzjbState='HN_LZJB_YWJ'
            updateLzjbinfo(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addLzjbinfo(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除廉正举报编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delLzjbinfo(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有廉正举报数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportLzjbinfo(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
<style>
  .file-preview{
    height: 100%;
    width: 100%;
  }
  .file-preview img{
    width: 100%;
    height: 500px;
    object-fit: contain;
  }
  .file-preview video{
    width: 100%;
    height: 500px;
    object-fit: contain;
  }
</style>
